import conf from "@/common/conf.js";
export default {
	/**
	 * 用户登录
	 */
	async loginManual(host) {
		// 清除缓存
		try {
			uni.clearStorageSync();
		} catch (e) {}

		// 获取凭据
		let code = await uni.login({
			provider: 'weixin',
			onlyAuthorize: true
		});
		console.log('wxCode->', code.code);

		// 请求token
		let res = await uni.request({
			url: host + '/weapps/login/',
			method: "POST",
			header: {
				'content-type': 'application/json'
			},
			data: {
				code: code.code
			}
		})
		console.log(res.data);

		// 写入缓存
		try {
			uni.setStorageSync('token', res.data.token);
			uni.setStorageSync('auth', res.data.auth);
			uni.setStorageSync('last', Date.now());
		} catch (e) {
			console.log('写入本地缓存失败');
		}
	},

}